package org.example.booksmanagementsystem.mapper;

import org.apache.ibatis.annotations.*;
import org.example.booksmanagementsystem.model.PageRequest;
import org.example.booksmanagementsystem.model.PageResult;
import org.example.booksmanagementsystem.model.UserInfo;

import java.util.List;

@Mapper
public interface UserInfoMapper {

    // 查询图书管理员的信息
    @Select("select id,user_name,password,delete_flag,create_time,update_time "+
            "updata_time from user_info where user_name= #{userName}")
    UserInfo queryUserInfoByUserName(String userName);

    // 查询普通用户的信息
    @Select("select id,user_name,password,delete_flag,create_time "+
            "updata_time from normal_user_info where user_name= #{userName}")
    UserInfo queryUserInfoByUserNameNormal(String userName);

    // 注册用户--创建普通用户
    @Insert("insert into normal_user_info (user_name,password) values(#{userName},#{password})")
    Integer insertUserInfo(UserInfo userInfo);

    //用户购买图书前，先为用户创建一个存图书的表格
    Integer createBooktable(Integer userId);

    Integer createSpecialBooktable(Integer userId);


    @Select("select id,user_name,password,delete_flag,create_time,update_time "+
            "from normal_user_info " +
            " order by id asc limit #{offset},#{pageSize}")
    List<UserInfo> queryNormalUserInfoList(PageRequest pageRequest);



    //普通用户的总数
    @Select("select count(*) from normal_user_info")
    Integer queryNormalUserInfoCount();

    @Select("select id,user_name,password from normal_user_info where id = #{id}")
    UserInfo getUserInfoById(Integer id);

    // 根据userName跟新密码
    @Update("update normal_user_info set password = #{password} where user_name =#{userName}")
    Integer updateNormalUserInfoPassword(UserInfo userInfo);

    //根据id删除用户--逻辑删除
    @Update("update normal_user_info set delete_flag=1 where id=#{id}")
    Integer updateUserStatus(Integer id);

    // 逻辑删除大量用户
    Integer updateBatchUserStatus(@Param("idList") List<Integer> idList);


}
